package com.jctrip.hotel.source.xxl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jctrip.hotel.common.constant.XxlJobNameConstant;
import com.jctrip.hotel.domain.entity.HtPriceCalendarCnbe;
import com.jctrip.hotel.source.service.basic.HtPriceCalendarCnbeService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: zxy
 * @CreateTime: 2023-08-18 10:42
 * @Description:
 */
@Component
@Slf4j
public class SyncHtCnbePriceCalendarDeleteXxlJob extends IJobHandler {
    @Autowired
    private HtPriceCalendarCnbeService htPriceCalendarCnbeService;

    @Override
    @XxlJob(XxlJobNameConstant.SYNC_HT_CNBE_PRICE_CALENDAR_DELETE_TASK)
    public void execute() throws Exception {
        XxlJobHelper.log(XxlJobNameConstant.SYNC_HT_CNBE_PRICE_CALENDAR_DELETE_TASK + " xxl job start");

        try {
            String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            htPriceCalendarCnbeService.remove(
                    new LambdaQueryWrapper<HtPriceCalendarCnbe>().lt(HtPriceCalendarCnbe::getCalDate, nowDate));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        XxlJobHelper.log(XxlJobNameConstant.SYNC_HT_CNBE_PRICE_CALENDAR_DELETE_TASK + " xxl job end");

    }
}